package com.kaki.mdb;

import com.healthmarketscience.jackcess.CryptCodecProvider;
import com.healthmarketscience.jackcess.Database;
import com.healthmarketscience.jackcess.DatabaseBuilder;
import net.ucanaccess.jdbc.JackcessOpenerInterface;

import java.io.File;
import java.io.IOException;

/**
 * @author Kaki Nakajima
 * @description DB Show CryptCodecOpener（一个加密解密的扩展库，用于打开受加密保护的 Microsoft Access 数据库）
 * @date 2025-06-24 20:08
 * CSDN: https://blog.csdn.net/tubing1996/article/details/130488193 参考
 */
public class CryptCodecOpener implements JackcessOpenerInterface {

    public Database open(File fl, String pwd) throws IOException {
        DatabaseBuilder dbd = new DatabaseBuilder(fl);
        dbd.setAutoSync(false);
        dbd.setCodecProvider(new CryptCodecProvider(pwd));
        dbd.setReadOnly(false);
        return dbd.open();
    }
}
